#include <led.h>

unsigned char temp=0x00,temp_old=0xff;

void led_display(unsigned char *ucLed)
{
	unsigned char i;
	temp=0x00;
	for(i=0;i<=7;i++)
	{
		temp|=ucLed[i]<<i;
	}
	if(temp!=temp_old){
		
		P0=~temp;
		P2=(P2&0x1f)|0x80;
		P2&=0x1f;
		temp_old=temp;
	}
	 
}
void led_off()
{
	P0 = 0xff;
    P2 = (P2 & 0x1f) | 0x80;
    P2 &= 0x1f;
	temp_old=0x00;
}


unsigned char temp0=0x00,temp_old0=0xff;

/**
 * @brief 蜂鸣器
 * @param enable 1:开 0:关
 */
void beep(bit enable){
	if (enable)
    	temp0 |= 0x40;
  	else
    	temp0 &= ~(0x40);

	if (temp0 != temp_old0)
	{
		P0 = temp0;
		P2 = P2 & 0x1f | 0xa0;
		P2 &= 0x1f;
		temp_old0 = temp0;
	}
}

/// @brief 继电器控制
/// @param enable	1:开 0:关
void relay(bit enable)
{
  if (enable)
    temp0 |= 0x10;
  else
    temp0 &= ~(0x10);
  if (temp0 != temp_old0)
  {
    P0 = temp0;
    P2 = P2 & 0x1f | 0xa0;
    P2 &= 0x1f;
    temp_old0 = temp0;
  }
}
/// @brief MOTOR控制
/// @param enable	1:开 0:关
void MOTOR(bit enable)
{
  if (enable)
    temp0 |= 0x20;
  else
    temp0 &= ~(0x20);
  if (temp0 != temp_old0)
  {
    P0 = temp0;
    P2 = P2 & 0x1f | 0xa0;
    P2 &= 0x1f;
    temp_old0 = temp0;
  }
}